package tests.page;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description: 后台管理页面
 * User: Spider-Man
 * Date: 2025-09-21
 * Time: 16:36
 */
public class ActivityManagementPage extends Utils {
    /**
     * 活动列表页
     */
    public void activityListPage() throws IOException {
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("#phoneNumber")).sendKeys("13087936712");//输入账号
        driver.findElement(By.cssSelector("#password")).sendKeys("111111");//输入密码
        driver.findElement(By.cssSelector("#loginForm > button")).click();
        WebElement element = driver.findElement(By.cssSelector("body > div.header-box > div.user-box > div > span"));
        String expect = element.getText();
        assert expect.equals("退出");
        element = driver.findElement(By.cssSelector("#activitiesList"));
        expect = element.getText();
        assert expect.equals("活动列表");
        //活动标题(切换到内嵌页面)
        driver.get("http://43.143.179.59:8080/activities-list.html");
        element = driver.findElement(By.cssSelector("#title"));
        expect = element.getText();
        assert expect.equals("测试活动3");
        //活动描述
        element = driver.findElement(By.cssSelector("#activities > div:nth-child(1) > div.activity-info > p"));
        expect = element.getText();
        assert expect.equals("测试活动3");
        //活动状态
        element = driver.findElement(By.cssSelector("#activities > div:nth-child(1) > div.inactive > p > a"));
        expect = element.getText();
        assert expect.equals("活动已完成，查看中奖名单");
        getScreenShot(Thread.currentThread().getName());
    }

    /**
     * 新建活动列表页
     */
    public void createActivityPage() throws IOException {
        driver.get("http://43.143.179.59:8080/create-activity.html");
        WebElement element = driver.findElement(By.cssSelector("body > div.container > h2"));
        String expect = element.getText();
        assert expect.equals("创建抽奖活动");
        element = driver.findElement(By.cssSelector("#activityForm > div:nth-child(1) > label"));
        expect = element.getText();
        assert expect.equals("活动名称");
        element = driver.findElement(By.cssSelector("#activityName"));
        expect = element.getAttribute("placeholder");
        assert expect.equals("请输入活动名称");
        element = driver.findElement(By.cssSelector("#activityForm > div.form-group.desc-row > label"));
        expect = element.getText();
        assert expect.equals("活动描述");
        element = driver.findElement(By.cssSelector("#description"));
        expect = element.getAttribute("placeholder");
        assert expect.equals("请输入活动描述");

        element = driver.findElement(By.cssSelector("#buttonPrizes"));
        expect = element.getText();
        assert expect.equals("圈选奖品");
        element = driver.findElement(By.cssSelector("#buttonUsers"));
        expect = element.getText();
        assert expect.equals("圈选人员");
        element = driver.findElement(By.cssSelector("#createActivity"));
        expect = element.getText();
        assert expect.equals("创建活动");
        getScreenShot(Thread.currentThread().getName());
        driver.findElement(By.cssSelector("body > div.header-box > div.user-box > div > span")).click();
    }


}
